﻿using HCQ2_Model;
using HCQ2_Model.VR.Model;
using HCQ2_Model.VR.Params;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HCQ2_BLL
{
    public partial class T_VRExperienceMainBLL
    {
        /// <summary>
        ///  获取课件所在目录
        /// </summary>
        /// <param name="file_id"></param>
        /// <returns></returns>
        public string GetFolderName(int file_id)
        {
            return DBSession.IT_VRExperienceMainDAL.GetFolderName(file_id);
        }
        /// <summary>
        ///  获取个人学校、班级信息
        /// </summary>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public ExperienceMainResult GetSchoolInfo(int user_id)
        {
            return DBSession.IT_VRExperienceMainDAL.GetSchoolInfo(user_id);
        }
        /// <summary>
        ///  获取单位班级数据
        /// </summary>
        /// <returns></returns>
        public UnitTreeModel GetUnitData()
        {
            UnitTreeModel result = new UnitTreeModel { name = "教学统计", unit_code = "", id = 0, pId = 0 };
            //1.0 获取全部班级
            List<T_Class> list = DBSession.IT_ClassDAL.Select(s => true);
            var query = list.Select(s => new { s.schoolCode, s.schoolName }).Distinct().ToList();
            List<UnitTreeModel> child = new List<UnitTreeModel>();
            for(int i = 0; i < query.Count; i++)
            {
                int tempId = i + 1;
                child.Add(new UnitTreeModel
                {
                    id = tempId,
                    pId = 0,
                    name = query[i].schoolName,
                    unit_code = query[i].schoolCode,
                    is_unit = true,
                    children = GetClass(list, query[i].schoolCode, tempId)
                });
            }
            result.children = child;
            return result;
        }

        /// <summary>
        ///  获取班级信息
        /// </summary>
        /// <param name="unit_code"></param>
        /// <returns></returns>
        private List<UnitTreeModel> GetClass(List<T_Class> list,string unit_code,int pid)
        {
            List<UnitTreeModel> model = new List<UnitTreeModel>();
            var query = list.Where(s => s.schoolCode.Equals(unit_code))?.ToList();
            query.ForEach(o =>
            {
                model.Add(new UnitTreeModel {
                    name=o.className,
                    id=o.id,
                    is_unit=false,
                    pId= pid
                });
            });
            return model;
        }
        /// <summary>
        ///  获取教学统计列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<T_VRExperienceMain> GetExperienceList(ExperienceParam param, out int total)
        {
            return DBSession.IT_VRExperienceMainDAL.GetExperienceList(param, out total);
        }
    }
}